<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>我的私信</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
    <script>
        $(function () {
            //拿到当前用户的对象
            var user = JSON.parse(sessionStorage.getItem("user"));
            var userId = user.id;
            //首先我们需要获取当前页的标签
            var currentInput = $('#currentPage');
            //因为我们手机滚动之前的数据就没有了,只有当前查出来的不合理
            var arr=[];
            var pages=1;
            var list=[];
            function query() {
                //获取当前页
                var currentPage = currentInput.val();
                $.get('/allMessages/' + userId,{currentPage:currentPage},function (data) {
                    console.log(data);
                    pages=data.privateMessagePageInfo.pages;
                    list = data.privateMessagePageInfo.list;
                    //把两个数组的数据合并在一起,就可以滚动了
                    $.merge(arr,data.privateMessagePageInfo.list);
                    var json = {list:arr};
                    console.log(json);
                    $('.aui-scrollView').renderValues(json,{
                        getHref:function (item,value) {
                            var href = $(item).data("href");
                            $(item).attr("href",href+value);
                        },
                        getNum:function (item,value) {
                            console.log(value);
                            if (value == 1) {
                                $(item).html("未读");
                            }else if (value == 2){
                                $(item).html("已读");
                                $(item).css('color','blue');
                            }
                        }
                    });

                });
                currentInput.val(parseInt(currentPage)+1);
            }
            query();
            $('._j_add_more_button').click(function () {
                var currentPage = currentInput.val();
                if(currentPage<=pages){
                    query();
                }else{
                    $(document).dialog({
                        type : 'notice',
                        infoText: '没有更多私信了!!!',
                        autoClose: 1000
                    });
                }
            });
        })
    </script>
</head>
<body>
<input type="hidden" id="currentPage" name="currentPgee" value="1">
<section class="aui-flexView">
    <header class="aui-navBar aui-navBar-fixed">
        <a href="/mine/message.html" class="aui-navBar-item">
            <i class="icon icon-return"></i>
        </a>
        <div class="aui-center">
            <span class="aui-center-title">我的私信</span>
        </div>
        <a href="javascript:;" class="aui-navBar-item">
            <i class="icon icon-sys"></i>
            <i class="icon icon-fre"></i>
        </a>
    </header>
    <section class="aui-scrollView">
        <div class="aui-news-box" render-loop="list">
            <a data-href="/mine/letterContent.html?id="  render-key="list.id" render-fun="getHref" class="aui-news-item">
                <div class="aui-news-item-hd">
                    <img render-src="list.user.headImgUrl" alt="">
                </div>
                <div class="aui-news-item-bd">
                    <h4 render-html="list.user.nickName"></h4>
                    <p render-html="list.messageContent"></p>
                </div>
                <div>
                    <p class="read" style="color: red" render-key="list.status" render-fun="getNum"></p>
                    <p>发送时间:</p>
                    <span class="aui-news-item-fr" render-html="list.sendTime"></span>
                </div>
            </a>
        </div>
        <div class="aui-news-box" style="text-align: center">
            <a class="more-list _j_add_more_button">更多私信</a>
        </div>
    </section>
</section>
</body>
</html>
